﻿using System.Collections.Generic;
using System.Linq;
using FPPrinter.Models.WpfDoc;

namespace FPPrinter.Models.Doc
{
    public class ShortOptimizedDoc : OptimizedDocBase
    {
        public override void Generate(IEnumerable<IImage> srcImages)
        {
            var pss = new List<IFPDocPage>();

            Images = srcImages;

            var images = srcImages.ToList();

            for (int i = 0; i < images.Count; i = i + 1)
            {
             
                if (i < images.Count-1  )
                { //
                    var i1 = images[i];
                    // IFPDocPage p = new FpShortDocPage(i1);
                    // pss.Add(p);

                    
                    var i2 = images[i + 1];
                    var p2 = new FpShortDocPage(i1, i2);
                    pss.Add(p2);
                    i++;
                }
                else
                {
                    // only 1 image in a page
                    var i1 = images[i];
                    IFPDocPage p = new FpShortDocPage(i1);
                    pss.Add(p);

                }
                 
            }

            base.Pages = pss;
            FixedDocWpf = this.ToFixedDocWpf();
        }
    }
}